<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class User extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('user_model');
		$this->load->library('parser');
    }

    public function index()
    {
        $data['user'] = $this->user_model->get_user();
        $data['title'] = 'User archive';

	//$this->load->view('templates/header', $data);
	$this->parser->parse('user/index', $data);
	//$this->load->view('templates/footer');
    }

    public function view($slug)
    {
        $data['user_item'] = $this->user_model->get_user($slug);

        if (empty($data['user_item']))
        {
            show_404();
        }

        $data['userid'] = $data['user_item']['userid'];
        $data['email'] = $data['user_item']['email'];

        $this->load->view('templates/header', $data);
        $this->load->view('user/view', $data);
        $this->load->view('templates/footer');
    }
    
    public function create()
{
	$this->load->helper('form');
	$this->load->library('form_validation');
	
	$data['title'] = 'New User';
	
	$this->form_validation->set_rules('userid', 'User Name', 'required');
	$this->form_validation->set_rules('email', 'Email', 'required');
	$this->form_validation->set_rules('password', 'Password', 'required');
	
	if ($this->form_validation->run() === FALSE)
	{
		$this->load->view('templates/header', $data);	
		$this->load->view('user/create');
		$this->load->view('templates/footer');
		
	}
	else
	{
		$this->user_model->set_user();
		$this->load->view('user/success');
	}
}
}
?>
